package cn.yunhe.services.impl;

import cn.yunhe.dao.IStudentDao;
import cn.yunhe.entity.*;
import cn.yunhe.services.IStudentServices;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 孙权庆 on 2018/5/22.
 */
@Service
public class StudentServices implements IStudentServices {

    @Resource
    private IStudentDao studentDao;

    /**
     * 检查登录
     * @param map
     * @return
     */
    @Override
    public Student checkLogin(Map map) {
        return studentDao.findByStudentName(map);
    }

    /**
     * 获得模拟试卷的多条件查询 条件的数据
     * @param cid
     * @return
     */
    @Override
    public Map<String, Object> getMnCondition(int cid) {
        Map<String,Object> map = new HashMap<>();

        //查询符合条件的课程
        List<Course> courses = studentDao.getCourses(cid);
        map.put("courses",courses);
        //查询符合条件的试卷类型
        List<Ptype> ptypes = studentDao.getPtypes();
        map.put("ptypes",ptypes);
        //查询符合条件的试卷时间 == 年
        List<String> years = studentDao.getPaperYears(cid);
        map.put("years",years);
        return map;
    }

    /**
     * 获得多条件查询后的数据
     * @param map
     * @return
     */
    @Override
    public Page getMcPapers(Map<String, Object> map) {
        Page page = new Page();
        //得到总条数
        int totalPages = studentDao.getMcPapersCount(map);
        page.setTotal(totalPages);

        //得到每页显示的总条数
        int pageSize = Integer.parseInt(String.valueOf(map.get("pageSize")));
        page.setPageSize(pageSize);
        //得到当前页
        int curPageNum = Integer.parseInt(String.valueOf(map.get("curPageNum")));
        page.setPageNum(curPageNum);

        page = PageHelper.startPage(curPageNum,pageSize);
        List<Paper> list = studentDao.getMcPapers(map);

        return page;
    }

    @Override
    public Page getCurrStuScores(Map<String,Object> map) {
        Page page = new Page();
        //得到总条数
        int totalPages = studentDao.getCurrStuScoresCount(map);
        page.setTotal(totalPages);

        //得到每页显示的总条数
        int pageSize = Integer.parseInt(String.valueOf(map.get("pageSize")));
        page.setPageSize(pageSize);
        //得到当前页
        int curPageNum = Integer.parseInt(String.valueOf(map.get("curPageNum")));
        page.setPageNum(curPageNum);

        page = PageHelper.startPage(curPageNum,pageSize);
        List<Score> list = studentDao.getCurrStuScores(map);
        return page;
    }


    @Override
    public List<Student> getLikeStudent() {

        return studentDao.getListStudent();
    }

    public IStudentDao getStudentDao() {
        return studentDao;
    }

    public void setStudentDao(IStudentDao studentDao) {
        this.studentDao = studentDao;
    }
}
